<%@ page contentType="text/html; charset=UTF-8" 
import="java.util.*,com.admin.User,com.admin.Role"

%> <% User user=(User)request.getSession().getAttribute("login_user");
    Role role=(Role)request.getSession().getAttribute("user_roles");
 %><%@ taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
%>
<head>
<link href="<%=path%>/css/bootstrap.min.css" rel="stylesheet">
<link href="<%=path%>/css/style.min.css" rel="stylesheet">
<link href="<%=path%>/css/materialdesignicons.min.css" rel="stylesheet">
<link href="<%=path%>/css/animate.css" rel="stylesheet">
<link href="<%=path%>/js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">

<link rel="stylesheet" href="<%=path%>/js/ion-rangeslider/ion.rangeSlider.min.css">
<link href="<%=path%>/js/jconfirm/jquery-confirm.min.css" rel="stylesheet">




<script type="text/javascript" src="<%=path%>/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/main.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/jconfirm/jquery-confirm.min.js"></script>

</head>
 <body style="background:#FFF" >



 <s:if test="Wtid != 0">
  
     <h3 id="title"><s:property value="wtxx.Wtname"/></h3>
      <div class="example-box" id="radios" style="display:none">
            <label class="lyear-radio  radio-primary m-t-10">
              <input type="radio" id="1" name="r1">
              <span>答案1</span>
            </label>
             <label class="lyear-radio  radio-primary m-t-10">
              <input type="radio" id="2" name="r1">
              <span>答案2</span>
            </label>
            <label class="lyear-radio  radio-primary m-t-10">
              <input type="radio" id="3" name="r1">
              <span>答案3</span>
            </label>
            
          </div> 
          <br>
          <div class="form-group">
          <div class="example-box" id="buttons1"  style="display:none">
                <button class="btn btn-w-md btn-round btn-primary" onclick="nextwt()">确定</button>
          </div> 
          </div>
          <div class="form-group">
          <div class="example-box" id="buttons2"  style="display:none">
                <button class="btn btn-w-md btn-round btn-yellow" onclick="sygwt()">上一题</button>
                 <button class="btn btn-w-md btn-round btn-primary" onclick="nextwt()">确定</button>
           </div> 
          </div>
         
   </s:if>
<s:else>
	 <p>决策树数据不存在或尚未完成决策树</p>		          
 </s:else>
		
 
 </body>
</html>
<script type="text/javascript">
var DMid = <s:property value="DMid" />;
var Wtid = "<s:property value="Wtid"/>";
if(Wtid != 0){
	xgradio(Wtid);   
}

function xgradio(Wtid){
	$.ajax({
 		type: "post",//方法类型
 	   dataType: "json",//预期服务器返回的数据类型 jsonp跨域
 		url: "<%=path%>/bg/getwtdadata",
 		data:{
 			"wtxx.Wtid":Wtid
 		},
 		success: function(req) {	
 			let data = req.data;
 			$('#radios')[0].innerHTML = "";
 			let radhtml = "";
 			for(var a=0;a<data.length;a++){
 				radhtml = radhtml+'<label class="lyear-radio radio-primary"><input type="radio" value="'+data[a].Wtdaid+'" onclick="buttonshow('+data[a].Wtdaid+',this);" name="r1">';
 				radhtml = radhtml+'<span>'+data[a].Daname+'</span></label>';
 			}
 			$('#radios')[0].innerHTML = radhtml;
 			
 			document.getElementById("radios").style.display ="block";
 				
 		},error: function(e){ 
 			console.log(e);
 			
 		}
 	});
	
}


function getnextwt(Wtdaids){
	//console.log(Wtdaids);
	$.ajax({
 		type: "post",//方法类型
 	   dataType: "json",//预期服务器返回的数据类型 jsonp跨域
 		url: "<%=path%>/bg/getnextwt",
 		data:{
 			"jcs.Wtdaids":Wtdaids.join(","),
 			"jcs.DMid":DMid
 		},
 		success: function(req) {	
 			
 			let data = req.data[0];
 			console.log(data);
 			if(req.results==2){
 			document.getElementById("radios").style.display ="none";
 			document.getElementById("buttons1").style.display ="none";
 			document.getElementById("buttons2").style.display ="block";
 			document.getElementById("title").innerText = data.Wtname;
 	 		xgradio(data.Wtid);	
 			}else{
 				if(data==undefined){
 					let xx = m.get(sygid);
 	 				tmsl = tmsl - 1; 
 	 				m.delete(sygid);
 	 				let index = Wtdaids.indexOf(sygid);
 	 				Wtdaids.splice(index, 1);
 	 				sygid = Wtdaids[Wtdaids.length-1]
 					 $.alert("暂无结论");	
 					
 				}else{
 				let xx = m.get(sygid);
 				tmsl = tmsl - 1; 
 				m.delete(sygid);
 				let index = Wtdaids.indexOf(sygid);
 				Wtdaids.splice(index, 1);
 				sygid = Wtdaids[Wtdaids.length-1]
 				
 			    window.parent.title = "结论";
            	let html = "<h3 style='font-size:17'>判定结果:</h3>"
            	html = html + "<p style='font-size:13'>"+data.Pdjl+"</p>";
            	html = html + "<h3 style='font-size:17'>判定依据:</h3>";
            	var snsArr=data.Pdyj.split("\r");
            	for(var a=0;a<snsArr.length;a++){
            		html = html + "<p style='font-size:13'>"+snsArr[a]+"</p>";	
            	}
            	html = html + "<h3 style='font-size:17'>研究内容:</h3>";
            	snsArr=data.Yjnr.split("\r");
            	for(var a=0;a<snsArr.length;a++){
            		html = html + "<p style='font-size:13'>"+snsArr[a]+"</p>";	
            	}
            	
            	window.parent.nrbody = html;
            	window.parent.test(); 
 				}
 			}
 			
 		},error: function(e){ 
 			console.log(e);
 			
 		}
 	});
}





var tmsl = 0;
function buttonshow(id,obj){
		
		if(tmsl==0){
			document.getElementById("buttons1").style.display ="block";	
			document.getElementById("buttons2").style.display ="none";	
	   		}else{
			document.getElementById("buttons2").style.display ="block";
			document.getElementById("buttons1").style.display ="none";	
		}
		
	}
	
var Wtdaids = new Array();
	var m = new Map(); // 空Map
   	var sygid = 0;
function nextwt(){
		
		var val=$('input:radio[name="r1"]:checked').val();
		if(val){
		tmsl = tmsl + 1; 
		sygid = val;
		Wtdaids.push(val);
		let xx = new Array();
		xx.title = document.getElementById("title").innerText; 
		xx.innerHTML = $('#radios')[0].innerHTML; 
		m.set(val,xx); // 添加新的key-value
		getnextwt(Wtdaids);
		
		}else{
		 $.alert("请选择内容");	
		}
}
	
function sygwt(){
	let xx = m.get(sygid);
	tmsl = tmsl - 1; 
	document.getElementById("radios").style.display ="none";
	document.getElementById("buttons1").style.display ="none";
	document.getElementById("buttons2").style.display ="none";
	document.getElementById("title").innerText = xx.title; 
	$('#radios')[0].innerHTML = xx.innerHTML;
	
	let val=$('input:radio[name="r1"]');
	for(var i=0;i<val.length;i++){
		if(val[i].value==sygid){
			val[i].checked = true;
		}
	}
	document.getElementById("radios").style.display ="block";
	if(tmsl==0){
			document.getElementById("buttons1").style.display ="block";	
			document.getElementById("buttons2").style.display ="none";	
	   		}else{
			document.getElementById("buttons2").style.display ="block";
			document.getElementById("buttons1").style.display ="none";	
		}	
	m.delete(sygid);
	let index = Wtdaids.indexOf(sygid);
	Wtdaids.splice(index, 1);
	sygid = Wtdaids[Wtdaids.length-1]

	//console.log(sygid);
	}	
	
	
</script>